function ergodicRoutes(routes, authKey, authority) {
  routes.forEach(element => {
    if (element.path === authKey) {
      if (!element.authority) element.authority = []; // eslint-disable-line
      Object.assign(element.authority, authority || []);
    } else if (element.routes) {
      ergodicRoutes(element.routes, authKey, authority);
    }
    return element;
  });
}

export function patchRoutes(authRoutes) {
  console.log('authRoutes', authRoutes);
  Object.keys(authRoutes).map(authKey =>
    ergodicRoutes(window.g_routes, authKey, authRoutes[authKey].authority)
  );
}
